from django.shortcuts import render
# _*_coding:utf-8_*_
# Create your views here.
from django.http import HttpResponse, JsonResponse
import HenDaFuinterface.InterFace.classification as classification
import HenDaFuinterface.InterFace.stylegoodslist as stylegoodslist
import HenDaFuinterface.InterFace.goodsdetail as goodsdetail
import HenDaFuinterface.InterFace.goodsfilter as goodsfilter
import json


# 返回商品分类
def get_product_group(request):
    return HttpResponse(classification.re_proudct_grpup(), content_type='application/json')


# 返回商品列表
def get_stylegoods_list(request):
    postbody = {}
    if request.method == 'POST':
        if request.body:  # post参数不为空的情况
            postbody = json.loads(request.body)  # 获取用户返回的post请求参数
            # print(postbody)
        else:
            # print(request.POST)
            pass

    return HttpResponse(stylegoodslist.re_stylegoods_list(postbody), content_type='application/json')


# 返回商品详情
def get_goods_detai(request):
    postbody = {}
    if request.method == 'POST':
        if request.body:  # post参数不为空的情况
            postbody = json.loads(request.body)
    else:  # POST参数为空的情况
        pass
    return HttpResponse(goodsdetail.re_goods_detail(postbody), content_type='application/json')


# 返回商品过滤
def get_goods_filter(request):
    postbody = {}
    if request.method == 'POST':
        if request.body:  # post参数不为空的情况
            postbody = json.loads(request.body)
    else:
        pass
    return HttpResponse(goodsfilter.re_goods_filter(postbody), content_type='application/json')
